Conversation
Summary of ChangesHello @maxim-ge, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refactors the branch handling logic within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
…ges/archive/2602/2602251222-pr-apply-switch-back
There was a problem hiding this comment.
Code Review
This pull request refactors the branch switching logic in cmd_apply to make it more robust. The cmd_ffdefault function is simplified to no longer switch back to the original branch, delegating that responsibility to the caller. In cmd_apply, this is handled by capturing the original branch, using an ERR trap for cleanup on failure, and passing the original branch to the pr command for the final switch-back on success. The changes are logical and improve the script's behavior. I've found one issue with the implementation of the ERR trap regarding variable expansion, which would prevent it from working as intended.
| if [[ "$pr_flag" == "true" ]]; then | ||
| prev_branch=$(cd "$project_dir" && git symbolic-ref --short HEAD) | ||
| (cd "$project_dir" && bash "$script_dir/_lib/pr.sh" ffdefault) | ||
| trap 'git -C "$project_dir" checkout "$prev_branch" 2>/dev/null || true' ERR |
There was a problem hiding this comment.
The variables $project_dir and $prev_branch are inside single quotes in the trap command. This prevents them from being expanded when the trap is defined. As a result, the trap would attempt to execute a command with literal, unexpanded variable names (e.g., git -C "$project_dir"), which will fail.
To ensure the variables are correctly expanded with their values when the trap is defined, you should use double quotes for the outer string and escape the inner double quotes.
| trap 'git -C "$project_dir" checkout "$prev_branch" 2>/dev/null || true' ERR | |
| trap "git -C \"$project_dir\" checkout \"$prev_branch\" 2>/dev/null || true" ERR |
Fix cmd_apply branch switch-back handling
Remove premature switch-back from cmd_ffdefault in pr.sh so it stays on the default branch after fast-forwarding. Move prev_branch capture in conf.sh cmd_apply to before the ffdefault call. Add ERR trap to restore the original branch on failure.